<!DOCTYPE html>
<!-- saved from url=(0047)https://www.cnblogs.com/onepixel/p/7674659.html -->
<html lang="zh-cn"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="referrer" content="origin">
    <title>十大经典排序算法（动图演示） - 一像素 - 博客园</title>
<meta property="og:description" content="0、算法概述 0.1 算法分类 十种常见排序算法可以分为两大类： 比较类排序：通过比较来决定元素间的相对次序，由于其时间复杂度不能突破O(nlogn)，因此也称为非线性时间比较类排序。 非比较类排序：">
    <link type="text/css" rel="stylesheet" href="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/blog-common.css">
<link id="MainCss" type="text/css" rel="stylesheet" href="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/bundle-LessIsMoreRight.css">
<link type="text/css" rel="stylesheet" href="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/256889.css">
<link id="mobile-style" media="only screen and (max-width: 767px)" type="text/css" rel="stylesheet" href="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/bundle-LessIsMoreRight-mobile.css">
    <link title="RSS" type="application/rss+xml" rel="alternate" href="https://www.cnblogs.com/onepixel/rss">
    <link title="RSD" type="application/rsd+xml" rel="EditURI" href="https://www.cnblogs.com/onepixel/rsd.xml">
<link type="application/wlwmanifest+xml" rel="wlwmanifest" href="https://www.cnblogs.com/onepixel/wlwmanifest.xml">
    <script src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/f.txt"></script><script src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/pubads_impl_rendering_319.js"></script><script async="" src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/analytics.js"></script><script src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/jquery-2.2.0.min.js"></script>
    <script>var currentBlogId=256889;var currentBlogApp='onepixel',cb_enable_mathjax=false;var isLogined=false;</script>
    <script src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/blog-common.js" type="text/javascript"></script>
<link rel="preload" href="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/f(1).txt" as="script"><script type="text/javascript" src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/f(1).txt"></script><script src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/pubads_impl_319.js" async=""></script><link rel="prefetch" href="https://tpc.googlesyndication.com/safeframe/1-0-32/html/container.html"></head>
<body>
<a name="top"></a>

<!--PageBeginHtml Block Begin-->
<a href="https://github.com/git-onepixel"><img style="position: absolute; top: 0; right: 0; border: 0" src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
<!--PageBeginHtml Block End-->

<div id="home">
<div id="header">
	<div id="blogTitle">
		
<!--done-->
<div class="title"><a id="Header1_HeaderTitle" class="headermaintitle" href="https://www.cnblogs.com/onepixel/">一像素</a></div>
<div class="subtitle"></div>



		
	</div><!--end: blogTitle 博客的标题和副标题 -->
	<div id="navigator">
		
<ul id="navList">
<li id="nav_sitehome"><a id="blog_nav_sitehome" class="menu" href="https://www.cnblogs.com/">博客园</a></li>
<li id="nav_myhome"><a id="blog_nav_myhome" class="menu" href="https://www.cnblogs.com/onepixel/">首页</a></li>
<li id="nav_newpost"><a id="blog_nav_newpost" class="menu" rel="nofollow" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">新随笔</a></li>
<li id="nav_contact"><a id="blog_nav_contact" class="menu" rel="nofollow" href="https://msg.cnblogs.com/send/%E4%B8%80%E5%83%8F%E7%B4%A0">联系</a></li>
<li id="nav_rss"><a id="blog_nav_rss" class="menu" href="https://www.cnblogs.com/onepixel/rss">订阅</a>
<!--<a id="blog_nav_rss_image" class="aHeaderXML" href="https://www.cnblogs.com/onepixel/rss"><img src="//www.cnblogs.com/images/xml.gif" alt="订阅" /></a>--></li>
<li id="nav_admin"><a id="blog_nav_admin" class="menu" rel="nofollow" href="https://i.cnblogs.com/">管理</a></li>
</ul>

		<div class="blogStats">
			
			<div id="blog_stats">
<!--done-->
随笔-33&nbsp;
文章-12&nbsp;
评论-359&nbsp;
</div>
			
		</div><!--end: blogStats -->
	</div><!--end: navigator 博客导航栏 -->
</div><!--end: header 头部 -->
<div id="main">
	<div id="mainContent">
	<div class="forFlow">
		
        <div id="post_detail">
<!--done-->
<div id="topics">
	<div class="post">
		<h1 class="postTitle">
			<a id="cb_post_title_url" class="postTitle2" href="https://www.cnblogs.com/onepixel/p/7674659.html">十大经典排序算法（动图演示）</a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			<div id="cnblogs_post_body" class="blogpost-body"><h3 id="排序算法说明">0、算法概述</h3>
<h4>0.1 算法分类<strong><br></strong></h4>
<p>十种常见排序算法可以分为两大类：</p>
<ul>
<li><strong>比较类排序</strong>：通过比较来决定元素间的相对次序，由于其时间复杂度不能突破O(nlogn)，因此也称为非线性时间比较类排序。</li>
<li><strong>非比较类排序</strong>：不通过比较来决定元素间的相对次序，它可以突破基于比较排序的时间下界，以线性时间运行，因此也称为线性时间非比较类排序。&nbsp;</li>
</ul>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20190306165258970-1789860540.png" alt="" width="655" height="521"></p>
<h4><span style="font-size: 1em;">0.2 算法复杂度</span></h4>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20180402133438219-1946132192.png" alt="" width="655" height="443"></p>
<p><strong>0.3 相关概念</strong></p>
<ul>
<li><strong>稳定</strong>：如果a原本在b前面，而a=b，排序之后a仍然在b的前面。</li>
<li><strong>不稳定</strong>：如果a原本在b的前面，而a=b，排序之后 a 可能会出现在 b 的后面。</li>
<li><strong>时间复杂度</strong>：对排序数据的总的操作次数。反映当n变化时，操作次数呈现什么规律。</li>
<li><strong>空间复杂度：</strong>是指算法在计算机</li>
</ul>
<p>内执行时所需存储空间的度量，它也是数据规模n的函数。&nbsp;</p>
<h3 id="1冒泡排序bubble-sort">1、冒泡排序（Bubble Sort）</h3>
<p>冒泡排序是一种简单的排序算法。它重复地走访过要排序的数列，一次比较两个元素，如果它们的顺序错误就把它们交换过来。走访数列的工作是重复地进行直到没有再需要交换，也就是说该数列已经排序完成。这个算法的名字由来是因为越小的元素会经由交换慢慢“浮”到数列的顶端。&nbsp;</p>
<h4 id="2算法描述和实现">1.1 算法描述</h4>
<ul>
<li>比较相邻的元素。如果第一个比第二个大，就交换它们两个；</li>
<li>对每一对相邻元素作同样的工作，从开始第一对到结尾的最后一对，这样在最后的元素应该会是最大的数；</li>
<li>针对所有的元素重复以上的步骤，除了最后一个；</li>
<li>重复步骤1~3，直到排序完成。</li>
























</ul>
<p><strong>1.2 动图演示</strong></p>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20171015223238449-2146169197.gif" alt="" width="681" height="212"></p>
<h4 id="2算法描述和实现">1.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_722554" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function bubbleSort(arr) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length;</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = 0; i &lt; len - 1; i++) {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = 0; j &lt; len - 1 - i; j++) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(arr[j] &gt; arr[j+1]) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 相邻元素两两对比</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">temp = arr[j+1];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 元素交换</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[j+1] = arr[j];</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[j] = temp;</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number13 index12 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h3 id="2选择排序selection-sort">2、选择排序（Selection Sort）</h3>
<p>选择排序(Selection-sort)是一种简单直观的排序算法。它的工作原理：首先在未排序序列中找到最小（大）元素，存放到排序序列的起始位置，然后，再从剩余未排序元素中继续寻找最小（大）元素，然后放到已排序序列的末尾。以此类推，直到所有元素均排序完毕。&nbsp;</p>
<h4 id="2算法描述和实现-1">2.1 算法描述</h4>
<p>n个记录的直接选择排序可经过n-1趟直接选择排序得到有序结果。具体算法描述如下：</p>
<ul>
<li>初始状态：无序区为R[1..n]，有序区为空；</li>
<li>第i趟排序(i=1,2,3…n-1)开始时，当前有序区和无序区分别为R[1..i-1]和R(i..n）。该趟排序从当前无序区中-选出关键字最小的记录 R[k]，将它与无序区的第1个记录R交换，使R[1..i]和R[i+1..n)分别变为记录个数增加1个的新有序区和记录个数减少1个的新无序区；</li>
<li>n-1趟结束，数组有序化了。</li>
</ul>
<h4 id="2算法描述和实现"><strong>2.2 动图演示</strong></h4>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20171015224719590-1433219824.gif" alt="" width="684" height="209">　　</p>
<h4 id="2算法描述和实现">2.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_188175" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function selectionSort(arr) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length;</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">minIndex, temp;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = 0; i &lt; len - 1; i++) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">minIndex = i;</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = i + 1; j &lt; len; j++) {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(arr[j] &lt; arr[minIndex]) {&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 寻找最小的数</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">minIndex = j;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 将最小数的索引保存</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">temp = arr[i];</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[i] = arr[minIndex];</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[minIndex] = temp;</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number16 index15 alt1"><code class="csharp plain">}&nbsp;</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4>2.4 算法分析</h4>
<p>表现最稳定的排序算法之一，因为无论什么数据进去都是O(n<sup>2</sup>)的时间复杂度，所以用到它的时候，数据规模越小越好。唯一的好处可能就是不占用额外的内存空间了吧。理论上讲，选择排序可能也是平时排序一般人想到的最多的排序方法了吧。</p>
<h3 id="3插入排序insertion-sort">3、插入排序（Insertion Sort）</h3>
<p>插入排序（Insertion-Sort）的算法描述是一种简单直观的排序算法。它的工作原理是通过构建有序序列，对于未排序数据，在已排序序列中从后向前扫描，找到相应位置并插入。</p>
<h4>3.1 算法描述</h4>
<p>一般来说，插入排序都采用in-place在数组上实现。具体算法描述如下：</p>
<ul>
<li>从第一个元素开始，该元素可以认为已经被排序；</li>
<li>取出下一个元素，在已经排序的元素序列中从后向前扫描；</li>
<li>如果该元素（已排序）大于新元素，将该元素移到下一位置；</li>
<li>重复步骤3，直到找到已排序的元素小于或者等于新元素的位置；</li>
<li>将新元素插入到该位置后；</li>
<li>重复步骤2~5。</li>
</ul>
<h4>3.2 动图演示</h4>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20171015225645277-1151100000.gif" alt="" width="671" height="418"></p>
<h4>3.2 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_855365" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function insertionSort(arr) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length;</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">preIndex, current;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = 1; i &lt; len; i++) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">preIndex = i - 1;</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">current = arr[i];</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">while</code> <code class="csharp plain">(preIndex &gt;= 0 &amp;&amp; arr[preIndex] &gt; current) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[preIndex + 1] = arr[preIndex];</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">preIndex--;</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[preIndex + 1] = current;</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number14 index13 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4>3.4 算法分析</h4>
<p>插入排序在实现上，通常采用in-place排序（即只需用到O(1)的额外空间的排序），因而在从后向前扫描过程中，需要反复把已排序元素逐步向后挪位，为最新元素提供插入空间。</p>
<h3 id="4希尔排序shell-sort">4、希尔排序（Shell Sort）</h3>
<p>1959年Shell发明，第一个突破O(n<sup>2</sup>)的排序算法，是简单插入排序的改进版。它与插入排序的不同之处在于，它会优先比较距离较远的元素。希尔排序又叫<strong>缩小增量排序</strong>。</p>
<h4><span style="font-size: 1em;">4.1 算法描述</span></h4>
<p>先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序，具体算法描述：</p>
<ul>
<li>选择一个增量序列t1，t2，…，tk，其中ti&gt;tj，tk=1；</li>
<li>按增量序列个数k，对序列进行k 趟排序；</li>
<li>每趟排序，根据对应的增量ti，将待排序列分割成若干长度为m 的子序列，分别对各子表进行直接插入排序。仅增量因子为1 时，整个序列作为一个表来处理，表长度即为整个序列的长度。</li>
</ul>
<h4>4.2 动图演示</h4>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20180331170017421-364506073.gif" alt=""></p>
<h4>4.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_767125" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp comments">// 修改于 2019-03-06</code></div><div class="line number2 index1 alt1"><code class="csharp plain">function shellSort(arr) {</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">gap = Math.floor(len / 2); gap &gt; 0; gap = Math.floor(gap / 2)) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp comments">// 注意：这里和动图演示的不一样，动图是分组执行，实际操作是多个分组交替执行</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = gap; i &lt; len; i++) {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">j = i;</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">current = arr[i];</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">while</code> <code class="csharp plain">(j - gap &gt;= 0 &amp;&amp; current &lt; arr[j - gap]) {</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[j] = arr[j - gap];</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">j = j - gap; </code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[j] = current;</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number17 index16 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4>4.4 算法分析</h4>
<p>希尔排序的核心在于间隔序列的设定。既可以提前设定好间隔序列，也可以动态的定义间隔序列。动态定义间隔序列的算法是《算法（第4版）》的合著者Robert Sedgewick提出的。　</p>
<h3 id="5归并排序merge-sort">5、归并排序（Merge Sort）</h3>
<p>归并排序是建立在归并操作上的一种有效的排序算法。该算法是采用分治法（Divide and Conquer）的一个非常典型的应用。将已有序的子序列合并，得到完全有序的序列；即先使每个子序列有序，再使子序列段间有序。若将两个有序表合并成一个有序表，称为2-路归并。&nbsp;</p>
<h4>5.1 算法描述</h4>
<ul>
<li>把长度为n的输入序列分成两个长度为n/2的子序列；</li>
<li>对这两个子序列分别采用归并排序；</li>
<li>将两个排序好的子序列合并成一个最终的排序序列。</li>
</ul>
<h4>5.2 动图演示</h4>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20171015230557043-37375010.gif" alt="" width="678" height="422"></p>
<h4>5.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_215587" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function mergeSort(arr) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length;</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(len &lt; 2) {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">middle = Math.floor(len / 2),</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">left = arr.slice(0, middle),</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">right = arr.slice(middle);</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">merge(mergeSort(left), mergeSort(right));</code></div><div class="line number10 index9 alt1"><code class="csharp plain">}</code></div><div class="line number11 index10 alt2">&nbsp;</div><div class="line number12 index11 alt1"><code class="csharp plain">function merge(left, right) {</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">result = [];</code></div><div class="line number14 index13 alt1">&nbsp;</div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">while</code> <code class="csharp plain">(left.length&gt;0 &amp;&amp; right.length&gt;0) {</code></div><div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(left[0] &lt;= right[0]) {</code></div><div class="line number17 index16 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">result.push(left.shift());</code></div><div class="line number18 index17 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">} </code><code class="csharp keyword">else</code> <code class="csharp plain">{</code></div><div class="line number19 index18 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">result.push(right.shift());</code></div><div class="line number20 index19 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number21 index20 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number22 index21 alt1">&nbsp;</div><div class="line number23 index22 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">while</code> <code class="csharp plain">(left.length)</code></div><div class="line number24 index23 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">result.push(left.shift());</code></div><div class="line number25 index24 alt2">&nbsp;</div><div class="line number26 index25 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">while</code> <code class="csharp plain">(right.length)</code></div><div class="line number27 index26 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">result.push(right.shift());</code></div><div class="line number28 index27 alt1">&nbsp;</div><div class="line number29 index28 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">result;</code></div><div class="line number30 index29 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4>5.4 算法分析</h4>
<p>归并排序是一种稳定的排序方法。和选择排序一样，归并排序的性能不受输入数据的影响，但表现比选择排序好的多，因为始终都是O(nlogn）的时间复杂度。代价是需要额外的内存空间。</p>
<h3 id="6快速排序quick-sort">6、快速排序（Quick Sort）</h3>
<p>快速排序的基本思想：通过一趟排序将待排记录分隔成独立的两部分，其中一部分记录的关键字均比另一部分的关键字小，则可分别对这两部分记录继续进行排序，以达到整个序列有序。</p>
<h4 id="2算法描述和实现-5">6.1 算法描述</h4>
<p>快速排序使用分治法来把一个串（list）分为两个子串（sub-lists）。具体算法描述如下：</p>
<ul>
<li>从数列中挑出一个元素，称为 “基准”（pivot）；</li>
<li>重新排序数列，所有元素比基准值小的摆放在基准前面，所有元素比基准值大的摆在基准的后面（相同的数可以到任一边）。在这个分区退出之后，该基准就处于数列的中间位置。这个称为分区（partition）操作；</li>
<li>递归地（recursive）把小于基准值元素的子数列和大于基准值元素的子数列排序。</li>
</ul>
<h4>6.2 动图演示</h4>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20171015230936371-1413523412.gif" alt="" width="682" height="212"></p>
<h4>6.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_718973" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function quickSort(arr, left, right) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">len = arr.length,</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">partitionIndex,</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">left = </code><code class="csharp keyword">typeof</code> <code class="csharp plain">left != </code><code class="csharp string">'number'</code> <code class="csharp plain">? 0 : left,</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">right = </code><code class="csharp keyword">typeof</code> <code class="csharp plain">right != </code><code class="csharp string">'number'</code> <code class="csharp plain">? len - 1 : right;</code></div><div class="line number6 index5 alt1">&nbsp;</div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(left &lt; right) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">partitionIndex = partition(arr, left, right);</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">quickSort(arr, left, partitionIndex-1);</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">quickSort(arr, partitionIndex+1, right);</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number13 index12 alt2"><code class="csharp plain">}</code></div><div class="line number14 index13 alt1">&nbsp;</div><div class="line number15 index14 alt2"><code class="csharp plain">function partition(arr, left ,right) {&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 分区操作</code></div><div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">pivot = left,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 设定基准值（pivot）</code></div><div class="line number17 index16 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">index = pivot + 1;</code></div><div class="line number18 index17 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = index; i &lt;= right; i++) {</code></div><div class="line number19 index18 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(arr[i] &lt; arr[pivot]) {</code></div><div class="line number20 index19 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">swap(arr, i, index);</code></div><div class="line number21 index20 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">index++;</code></div><div class="line number22 index21 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></div><div class="line number23 index22 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number24 index23 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">swap(arr, pivot, index - 1);</code></div><div class="line number25 index24 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">index-1;</code></div><div class="line number26 index25 alt1"><code class="csharp plain">}</code></div><div class="line number27 index26 alt2">&nbsp;</div><div class="line number28 index27 alt1"><code class="csharp plain">function swap(arr, i, j) {</code></div><div class="line number29 index28 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">temp = arr[i];</code></div><div class="line number30 index29 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[i] = arr[j];</code></div><div class="line number31 index30 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[j] = temp;</code></div><div class="line number32 index31 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h3 id="7堆排序heap-sort">7、堆排序（Heap Sort）</h3>
<p>堆排序（Heapsort）是指利用堆这种数据结构所设计的一种排序算法。堆积是一个近似完全二叉树的结构，并同时满足堆积的性质：即子结点的键值或索引总是小于（或者大于）它的父节点。</p>
<h4>7.1 算法描述</h4>
<ul>
<li>将初始待排序关键字序列(R1,R2….Rn)构建成大顶堆，此堆为初始的无序区；</li>
<li>将堆顶元素R[1]与最后一个元素R[n]交换，此时得到新的无序区(R1,R2,……Rn-1)和新的有序区(Rn),且满足R[1,2…n-1]&lt;=R[n]；</li>
<li>由于交换后新的堆顶R[1]可能违反堆的性质，因此需要对当前无序区(R1,R2,……Rn-1)调整为新堆，然后再次将R[1]与无序区最后一个元素交换，得到新的无序区(R1,R2….Rn-2)和新的有序区(Rn-1,Rn)。不断重复此过程直到有序区的元素个数为n-1，则整个排序过程完成。</li>
</ul>
<h4>7.2 动图演示</h4>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20171015231308699-356134237.gif" alt=""></p>
<h4>7.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_320494" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div><div class="line number34 index33 alt1">34</div><div class="line number35 index34 alt2">35</div><div class="line number36 index35 alt1">36</div><div class="line number37 index36 alt2">37</div><div class="line number38 index37 alt1">38</div><div class="line number39 index38 alt2">39</div><div class="line number40 index39 alt1">40</div><div class="line number41 index40 alt2">41</div><div class="line number42 index41 alt1">42</div><div class="line number43 index42 alt2">43</div><div class="line number44 index43 alt1">44</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp keyword">var</code> <code class="csharp plain">len;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 因为声明的多个函数都需要数据长度，所以把len设置成为全局变量</code></div><div class="line number2 index1 alt1">&nbsp;</div><div class="line number3 index2 alt2"><code class="csharp plain">function buildMaxHeap(arr) {&nbsp;&nbsp; </code><code class="csharp comments">// 建立大顶堆</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">len = arr.length;</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = Math.floor(len/2); i &gt;= 0; i--) {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">heapify(arr, i);</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number8 index7 alt1"><code class="csharp plain">}</code></div><div class="line number9 index8 alt2">&nbsp;</div><div class="line number10 index9 alt1"><code class="csharp plain">function heapify(arr, i) {&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 堆调整</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">left = 2 * i + 1,</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">right = 2 * i + 2,</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">largest = i;</code></div><div class="line number14 index13 alt1">&nbsp;</div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(left &lt; len &amp;&amp; arr[left] &gt; arr[largest]) {</code></div><div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">largest = left;</code></div><div class="line number17 index16 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number18 index17 alt1">&nbsp;</div><div class="line number19 index18 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(right &lt; len &amp;&amp; arr[right] &gt; arr[largest]) {</code></div><div class="line number20 index19 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">largest = right;</code></div><div class="line number21 index20 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number22 index21 alt1">&nbsp;</div><div class="line number23 index22 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(largest != i) {</code></div><div class="line number24 index23 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">swap(arr, i, largest);</code></div><div class="line number25 index24 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">heapify(arr, largest);</code></div><div class="line number26 index25 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number27 index26 alt2"><code class="csharp plain">}</code></div><div class="line number28 index27 alt1">&nbsp;</div><div class="line number29 index28 alt2"><code class="csharp plain">function swap(arr, i, j) {</code></div><div class="line number30 index29 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">temp = arr[i];</code></div><div class="line number31 index30 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[i] = arr[j];</code></div><div class="line number32 index31 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[j] = temp;</code></div><div class="line number33 index32 alt2"><code class="csharp plain">}</code></div><div class="line number34 index33 alt1">&nbsp;</div><div class="line number35 index34 alt2"><code class="csharp plain">function heapSort(arr) {</code></div><div class="line number36 index35 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">buildMaxHeap(arr);</code></div><div class="line number37 index36 alt2">&nbsp;</div><div class="line number38 index37 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = arr.length - 1; i &gt; 0; i--) {</code></div><div class="line number39 index38 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">swap(arr, 0, i);</code></div><div class="line number40 index39 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">len--;</code></div><div class="line number41 index40 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">heapify(arr, 0);</code></div><div class="line number42 index41 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number43 index42 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number44 index43 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h3 id="8计数排序counting-sort">8、计数排序（Counting Sort）</h3>
<p>计数排序不是基于比较的排序算法，其核心在于将输入的数据值转化为键存储在额外开辟的数组空间中。 作为一种线性时间复杂度的排序，计数排序要求输入的数据必须是有确定范围的整数。</p>
<h4 id="3算法分析-5">8.1 算法描述</h4>
<ul>
<li>找出待排序的数组中最大和最小的元素；</li>
<li>统计数组中每个值为i的元素出现的次数，存入数组C的第i项；</li>
<li>对所有的计数累加（从C中的第一个元素开始，每一项和前一项相加）；</li>
<li>反向填充目标数组：将每个元素i放在新数组的第C(i)项，每放一个元素就将C(i)减去1。</li>
</ul>
<h4 id="3算法分析-5">8.2 动图演示</h4>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20171015231740840-6968181.gif" alt="" width="690" height="380"></p>
<h4 id="3算法分析-5">8.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_310302" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function countingSort(arr, maxValue) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">bucket = </code><code class="csharp keyword">new</code> <code class="csharp plain">Array(maxValue + 1),</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">sortedIndex = 0;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arrLen = arr.length,</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">bucketLen = maxValue + 1;</code></div><div class="line number6 index5 alt1">&nbsp;</div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = 0; i &lt; arrLen; i++) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(!bucket[arr[i]]) {</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">bucket[arr[i]] = 0;</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">bucket[arr[i]]++;</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2">&nbsp;</div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = 0; j &lt; bucketLen; j++) {</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">while</code><code class="csharp plain">(bucket[j] &gt; 0) {</code></div><div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[sortedIndex++] = j;</code></div><div class="line number17 index16 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">bucket[j]--;</code></div><div class="line number18 index17 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number19 index18 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number20 index19 alt1">&nbsp;</div><div class="line number21 index20 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number22 index21 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="3算法分析-5">8.4 算法分析</h4>
<p>计数排序是一个稳定的排序算法。当输入的元素是 n 个 0到 k 之间的整数时，时间复杂度是O(n+k)，空间复杂度也是O(n+k)，其排序速度快于任何比较排序算法。当k不是很大并且序列比较集中时，计数排序是一个很有效的排序算法。</p>
<h3 id="9桶排序bucket-sort">9、桶排序（Bucket Sort）</h3>
<p>桶排序是计数排序的升级版。它利用了函数的映射关系，高效与否的关键就在于这个映射函数的确定。桶排序 (Bucket sort)的工作的原理：假设输入数据服从均匀分布，将数据分到有限数量的桶里，每个桶再分别排序（有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排）。</p>
<h4 id="3算法分析-5">9.1 算法描述</h4>
<ul>
<li>设置一个定量的数组当作空桶；</li>
<li>遍历输入数据，并且把数据一个一个放到对应的桶里去；</li>
<li>对每个不是空的桶进行排序；</li>
<li>从不是空的桶里把排好序的数据拼接起来。&nbsp;</li>
</ul>
<h4>9.2 图片演示</h4>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20171015232107090-1920702011.png" alt=""></p>
<h4>9.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_825734" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div><div class="line number34 index33 alt1">34</div><div class="line number35 index34 alt2">35</div><div class="line number36 index35 alt1">36</div><div class="line number37 index36 alt2">37</div><div class="line number38 index37 alt1">38</div><div class="line number39 index38 alt2">39</div><div class="line number40 index39 alt1">40</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">function bucketSort(arr, bucketSize) {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(arr.length === 0) {</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number5 index4 alt2">&nbsp;</div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">i;</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">minValue = arr[0];</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">maxValue = arr[0];</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(i = 1; i &lt; arr.length; i++) {</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(arr[i] &lt; minValue) {</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">minValue = arr[i];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 输入数据的最小值</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">} </code><code class="csharp keyword">else</code> <code class="csharp keyword">if</code> <code class="csharp plain">(arr[i] &gt; maxValue) {</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">maxValue = arr[i];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 输入数据的最大值</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number16 index15 alt1">&nbsp;</div><div class="line number17 index16 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp comments">// 桶的初始化</code></div><div class="line number18 index17 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">DEFAULT_BUCKET_SIZE = 5;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 设置桶的默认数量为5</code></div><div class="line number19 index18 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">bucketSize = bucketSize || DEFAULT_BUCKET_SIZE;</code></div><div class="line number20 index19 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">bucketCount = Math.floor((maxValue - minValue) / bucketSize) + 1;&nbsp;&nbsp; </code></div><div class="line number21 index20 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">buckets = </code><code class="csharp keyword">new</code> <code class="csharp plain">Array(bucketCount);</code></div><div class="line number22 index21 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(i = 0; i &lt; buckets.length; i++) {</code></div><div class="line number23 index22 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">buckets[i] = [];</code></div><div class="line number24 index23 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number25 index24 alt2">&nbsp;</div><div class="line number26 index25 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp comments">// 利用映射函数将数据分配到各个桶中</code></div><div class="line number27 index26 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(i = 0; i &lt; arr.length; i++) {</code></div><div class="line number28 index27 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">buckets[Math.floor((arr[i] - minValue) / bucketSize)].push(arr[i]);</code></div><div class="line number29 index28 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number30 index29 alt1">&nbsp;</div><div class="line number31 index30 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr.length = 0;</code></div><div class="line number32 index31 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(i = 0; i &lt; buckets.length; i++) {</code></div><div class="line number33 index32 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">insertionSort(buckets[i]);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code><code class="csharp comments">// 对每个桶进行排序，这里使用了插入排序</code></div><div class="line number34 index33 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = 0; j &lt; buckets[i].length; j++) {</code></div><div class="line number35 index34 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr.push(buckets[i][j]);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></div><div class="line number36 index35 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number37 index36 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number38 index37 alt1">&nbsp;</div><div class="line number39 index38 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number40 index39 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="3算法分析-7">9.4 算法分析</h4>
<p>桶排序最好情况下使用线性时间O(n)，桶排序的时间复杂度，取决与对各个桶之间数据进行排序的时间复杂度，因为其它部分的时间复杂度都为O(n)。很显然，桶划分的越小，各个桶之间的数据越少，排序所用的时间也会越少。但相应的空间消耗就会增大。&nbsp;</p>
<h3 id="10基数排序radix-sort">10、基数排序（Radix Sort）</h3>
<p>基数排序是按照低位先排序，然后收集；再按照高位排序，然后再收集；依次类推，直到最高位。有时候有些属性是有优先级顺序的，先按低优先级排序，再按高优先级排序。最后的次序就是高优先级高的在前，高优先级相同的低优先级高的在前。</p>
<h4 id="2算法描述和实现-9">10.1 算法描述</h4>
<ul>
<li>取得数组中的最大数，并取得位数；</li>
<li>arr为原始数组，从最低位开始取每个位组成radix数组；</li>
<li>对radix进行计数排序（利用计数排序适用于小范围数的特点）；</li>
</ul>
<h4>10.2 动图演示</h4>
<p><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/849589-20171015232453668-1397662527.gif" alt="" width="686" height="389">&nbsp;</p>
<h4>10.3 代码实现</h4>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_400845" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp keyword">var</code> <code class="csharp plain">counter = [];</code></div><div class="line number2 index1 alt1"><code class="csharp plain">function radixSort(arr, maxDigit) {</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">mod = 10;</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">dev = 1;</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">i = 0; i &lt; maxDigit; i++, dev *= 10, mod *= 10) {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code><code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = 0; j &lt; arr.length; j++) {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">bucket = parseInt((arr[j] % mod) / dev);</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code><code class="csharp plain">(counter[bucket]==</code><code class="csharp keyword">null</code><code class="csharp plain">) {</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">counter[bucket] = [];</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">counter[bucket].push(arr[j]);</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">pos = 0;</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code><code class="csharp plain">(</code><code class="csharp keyword">var</code> <code class="csharp plain">j = 0; j &lt; counter.length; j++) {</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">var</code> <code class="csharp plain">value = </code><code class="csharp keyword">null</code><code class="csharp plain">;</code></div><div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code><code class="csharp plain">(counter[j]!=</code><code class="csharp keyword">null</code><code class="csharp plain">) {</code></div><div class="line number17 index16 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">while</code> <code class="csharp plain">((value = counter[j].shift()) != </code><code class="csharp keyword">null</code><code class="csharp plain">) {</code></div><div class="line number18 index17 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">arr[pos++] = value;</code></div><div class="line number19 index18 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number20 index19 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number21 index20 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number22 index21 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number23 index22 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">arr;</code></div><div class="line number24 index23 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="3算法分析-8">10.4 算法分析</h4>
<p>基数排序基于分别排序，分别收集，所以是稳定的。但基数排序的性能比桶排序要略差，每一次关键字的桶分配都需要O(n)的时间复杂度，而且分配之后得到新的关键字序列又需要O(n)的时间复杂度。假如待排数据可以分为d个关键字，则基数排序的时间复杂度将是O(d*2n) ，当然d要远远小于n，因此基本上还是线性级别的。</p>
<p>基数排序的空间复杂度为O(n+k)，其中k为桶的数量。一般来说n&gt;&gt;k，因此额外空间需要大概n个左右。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>　　</p></div><div id="MySignature"></div>
<div class="clear"></div>
<div id="blog_post_info_block">
<div id="BlogPostCategory">分类: <a href="https://www.cnblogs.com/onepixel/category/1193519.html" target="_blank">算法</a></div>
<div id="EntryTag"></div>
<div id="blog_post_info"><div id="green_channel">
        <a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(7674659,cb_blogId,1);green_channel_success(this,&#39;谢谢推荐！&#39;);">好文要顶</a>
            <a id="green_channel_follow" onclick="follow(&#39;c25fd669-c698-e511-9fc1-ac853d9f53cc&#39;);" href="javascript:void(0);">关注我</a>
    <a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a>
    <a id="green_channel_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/icon_weibo_24.png" alt=""></a>
    <a id="green_channel_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/wechat.png" alt=""></a>
</div>
<div id="author_profile">
    <div id="author_profile_info" class="author_profile_info">
            <a href="http://home.cnblogs.com/u/onepixel/" target="_blank"><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/20151205235751.png" class="author_avatar" alt=""></a>
        <div id="author_profile_detail" class="author_profile_info">
            <a href="http://home.cnblogs.com/u/onepixel/">一像素</a><br>
            <a href="http://home.cnblogs.com/u/onepixel/followees">关注 - 31</a><br>
            <a href="http://home.cnblogs.com/u/onepixel/followers">粉丝 - 853</a>
        </div>
    </div>
    <div class="clear"></div>
    <div id="author_profile_honor"></div>
    <div id="author_profile_follow">
                <a href="javascript:void(0);" onclick="follow(&#39;c25fd669-c698-e511-9fc1-ac853d9f53cc&#39;);return false;">+加关注</a>
    </div>
</div>
<div id="div_digg">
    <div class="diggit" onclick="votePost(7674659,&#39;Digg&#39;)">
        <span class="diggnum" id="digg_count">117</span>
    </div>
    <div class="buryit" onclick="votePost(7674659,&#39;Bury&#39;)">
        <span class="burynum" id="bury_count">0</span>
    </div>
    <div class="clear"></div>
    <div class="diggword" id="digg_tips">
    </div>
</div>
<script type="text/javascript">
    currentDiggType = 0;
</script></div>
<div class="clear"></div>
<div id="post_next_prev"><a href="https://www.cnblogs.com/onepixel/p/7468343.html" class="p_n_p_prefix">« </a> 上一篇：<a href="https://www.cnblogs.com/onepixel/p/7468343.html" title="发布于2017-09-02 23:12">小端字节序与大端字节序</a><br><a href="https://www.cnblogs.com/onepixel/p/8724526.html" class="p_n_p_prefix">» </a> 下一篇：<a href="https://www.cnblogs.com/onepixel/p/8724526.html" title="发布于2018-04-05 22:12">简单介绍 CPU 的工作原理</a><br></div>
</div>


		</div>
		<div class="postDesc">posted @ <span id="post-date">2017-10-15 23:43</span> <a href="https://www.cnblogs.com/onepixel/">一像素</a> 阅读(<span id="post_view_count">276821</span>) 评论(<span id="post_comment_count">56</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=7674659" rel="nofollow">编辑</a> <a href="https://www.cnblogs.com/onepixel/p/7674659.html#" onclick="AddToWz(7674659);return false;">收藏</a></div>
	</div>
	<script type="text/javascript">var allowComments=true,cb_blogId=256889,cb_entryId=7674659,cb_blogApp=currentBlogApp,cb_blogUserGuid='c25fd669-c698-e511-9fc1-ac853d9f53cc',cb_entryCreatedDate='2017/10/15 23:43:00';loadViewCount(cb_entryId);var cb_postType=1;var isMarkdown=false;</script>
	
</div><!--end: topics 文章、评论容器-->
</div><a name="!comments"></a><div id="blog-comments-placeholder"><div id="comments_pager_top"><div class="pager"><a href="https://www.cnblogs.com/onepixel/p/7674659.html#!comments" onclick="commentManager.renderComments(1,50);return false;">&lt; Prev</a><a href="https://www.cnblogs.com/onepixel/p/7674659.html#!comments" onclick="commentManager.renderComments(1,50);return false;">1</a><span class="current">2</span></div></div>
<!--done-->
<div class="feedback_area_title">评论列表</div>
<div class="feedbackNoItems"></div>
	

		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="https://www.cnblogs.com/onepixel/p/7674659.html#4160095" class="layer">#51楼</a><a name="4160095" id="comment_anchor_4160095"></a>  <span class="comment_date">2019-01-10 15:51</span> <a id="a_comment_author_4160095" href="https://www.cnblogs.com/Qiansion/" target="_blank">苏打水了面包</a> <a href="http://msg.cnblogs.com/send/%E8%8B%8F%E6%89%93%E6%B0%B4%E4%BA%86%E9%9D%A2%E5%8C%85" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_4160095" class="blog_comment_body">转一下</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4160095,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4160095,&#39;Bury&#39;,this)">反对(0)</a></div><span id="comment_4160095_avatar" style="display:none;">http://pic.cnblogs.com/face/1509242/20190319120204.png</span>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="https://www.cnblogs.com/onepixel/p/7674659.html#4165111" class="layer">#52楼</a><a name="4165111" id="comment_anchor_4165111"></a>  <span class="comment_date">2019-01-17 15:24</span> <a id="a_comment_author_4165111" href="http://home.cnblogs.com/u/866073/" target="_blank">kjcx100</a> <a href="http://msg.cnblogs.com/send/kjcx100" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_4165111" class="blog_comment_body">厉害了</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4165111,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4165111,&#39;Bury&#39;,this)">反对(0)</a></div>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="https://www.cnblogs.com/onepixel/p/7674659.html#4173043" class="layer">#53楼</a><a name="4173043" id="comment_anchor_4173043"></a>  <span class="comment_date">2019-01-28 18:43</span> <a id="a_comment_author_4173043" href="http://home.cnblogs.com/u/1043537/" target="_blank">大麻9</a> <a href="http://msg.cnblogs.com/send/%E5%A4%A7%E9%BA%BB9" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_4173043" class="blog_comment_body">那个希尔排序的代码，这行应为：<br> for (var j = i - gap; j &gt;=0 &amp;&amp; arr[j] &gt; temp; j -= gap)<br>大于或等于0</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4173043,&#39;Digg&#39;,this)">支持(2)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4173043,&#39;Bury&#39;,this)">反对(0)</a></div>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="https://www.cnblogs.com/onepixel/p/7674659.html#4188833" class="layer">#54楼</a><a name="4188833" id="comment_anchor_4188833"></a>  <span class="comment_date">2019-02-26 21:03</span> <a id="a_comment_author_4188833" href="http://home.cnblogs.com/u/1604909/" target="_blank">张浩南</a> <a href="http://msg.cnblogs.com/send/%E5%BC%A0%E6%B5%A9%E5%8D%97" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_4188833" class="blog_comment_body">语言精辟，动画visualgo上面更简练，对我归纳有很大帮助，加快理解，谢谢作者</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4188833,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4188833,&#39;Bury&#39;,this)">反对(0)</a></div>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="https://www.cnblogs.com/onepixel/p/7674659.html#4198340" class="layer">#55楼</a><a name="4198340" id="comment_anchor_4198340"></a>  <span class="comment_date">2019-03-10 19:29</span> <a id="a_comment_author_4198340" href="https://www.cnblogs.com/1-434/" target="_blank">yuhui.Mr</a> <a href="http://msg.cnblogs.com/send/yuhui.Mr" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_4198340" class="blog_comment_body">转一下</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4198340,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4198340,&#39;Bury&#39;,this)">反对(0)</a></div><span id="comment_4198340_avatar" style="display:none;">http://pic.cnblogs.com/face/803901/20190311132000.png</span>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="https://www.cnblogs.com/onepixel/p/7674659.html#4205189" class="layer">#56楼</a><a name="4205189" id="comment_anchor_4205189"></a><span id="comment-maxId" style="display:none;">4205189</span><span id="comment-maxDate" style="display:none;">2019/3/17 16:38:54</span>  <span class="comment_date">2019-03-17 16:38</span> <a id="a_comment_author_4205189" href="https://www.cnblogs.com/xiaozhch5/" target="_blank">xiaozhch5</a> <a href="http://msg.cnblogs.com/send/xiaozhch5" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_4205189" class="blog_comment_body">这也太棒了！！！<br>转一下</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4205189,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4205189,&#39;Bury&#39;,this)">反对(0)</a></div><span id="comment_4205189_avatar" style="display:none;">http://pic.cnblogs.com/face/1629592/20190313124556.png</span>
			</div>
		</div>
	<div id="comments_pager_bottom"><div class="pager"><a href="https://www.cnblogs.com/onepixel/p/7674659.html#!comments" onclick="commentManager.renderComments(1,50);return false;">&lt; Prev</a><a href="https://www.cnblogs.com/onepixel/p/7674659.html#!comments" onclick="commentManager.renderComments(1,50);return false;">1</a><span class="current">2</span></div></div></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
<div id="comment_form" class="commentform">
<a name="commentform"></a>
<div id="divCommentShow"></div>
<div id="comment_nav"><span id="span_refresh_tips"></span><a href="javascript:void(0);" onclick="return RefreshCommentList();" id="lnk_RefreshComments" runat="server" clientidmode="Static">刷新评论</a><a href="https://www.cnblogs.com/onepixel/p/7674659.html#" onclick="return RefreshPage();">刷新页面</a><a href="https://www.cnblogs.com/onepixel/p/7674659.html#top">返回顶部</a></div>
<div id="comment_form_container"><div class="login_tips">注册用户登录后才能发表评论，请 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return login(&#39;commentform&#39;);">登录</a> 或 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return register();">注册</a>，<a href="http://www.cnblogs.com/">访问</a>网站首页。</div></div>
<div class="ad_text_commentbox" id="ad_text_under_commentbox"></div>
<div id="ad_t2"><a href="https://edu.51cto.com/px/train/248?bky" target="_blank" onclick="ga(&#39;send&#39;, &#39;event&#39;, &#39;Link&#39;, &#39;click&#39;, &#39;T2-51CTO&#39;)">【幸运】99%的人不知道我们有可以帮你薪资翻倍的秘笈！</a><br><a href="http://www.ucancode.com/index.htm" target="_blank" onclick="ga(&#39;send&#39;, &#39;event&#39;, &#39;Link&#39;, &#39;click&#39;, &#39;T2-工控&#39;)">【推荐】超50万C++/C#源码: 大型实时仿真组态图形源码</a><br><a href="https://cloud.baidu.com/campaign/purchase-2019/index.html?track=cp:dsp|pf:pc|pp:chui-bokeyuan-huodong-19caigouji-BCC-neiyeCH-190311|pu:neiyeCH-wenzilian|ci:2019cgj|kw:2105959" target="_blank" onclick="ga(&#39;send&#39;, &#39;event&#39;, &#39;Link&#39;, &#39;click&#39;, &#39;T2-百度云&#39;)">【推荐】百度云“猪”你开年行大运，红包疯狂拿</a><br></div>
<div id="opt_under_post"></div>
<script async="async" src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/gpt.js"></script>
<script>
  var googletag = googletag || {};
  googletag.cmd = googletag.cmd || [];
</script>
<script>
  googletag.cmd.push(function() {
        googletag.defineSlot('/1090369/C1', [300, 250], 'div-gpt-ad-1546353474406-0').addService(googletag.pubads());
        googletag.defineSlot('/1090369/C2', [468, 60], 'div-gpt-ad-1539008685004-0').addService(googletag.pubads());
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
  });
</script>
<div id="cnblogs_c1" class="c_ad_block">
    <div id="div-gpt-ad-1546353474406-0" style="height: 250px; width: 300px;"><div id="google_ads_iframe_/1090369/C1_0__container__" style="border: 0pt none; width: 300px; height: 250px;"></div></div>
</div>
<div id="under_post_news"><div class="itnews c_ad_block"><b>相关博文：</b><br>·  <a href="https://www.cnblogs.com/jztan/p/5878630.html" target="_blank" onclick="clickRecomItmem(5878630)">十大经典排序算法总结（JavaScript描述）</a><br>·  <a href="https://www.cnblogs.com/chunguang/p/5892768.html" target="_blank" onclick="clickRecomItmem(5892768)">十大经典排序算法</a><br>·  <a href="https://www.cnblogs.com/kkun/archive/2011/11/23/bubble_sort.html" target="_blank" onclick="clickRecomItmem(2260280)">经典排序算法 - 冒泡排序Bubble sort</a><br>·  <a href="https://www.cnblogs.com/dushao/p/6004883.html" target="_blank" onclick="clickRecomItmem(6004883)">JS的十大经典算法排序</a><br>·  <a href="https://www.cnblogs.com/kkun/archive/2011/11/23/2260312.html" target="_blank" onclick="clickRecomItmem(2260312)">[经典排序算法][集锦]</a><br></div></div>
<div id="cnblogs_c2" class="c_ad_block">
    <div id="div-gpt-ad-1539008685004-0" style="height: 60px; width: 468px;"><div id="google_ads_iframe_/1090369/C2_0__container__" style="border: 0pt none; width: 468px; height: 60px;"></div></div>
</div>
<div id="under_post_kb"><div class="itnews c_ad_block"><b>最新新闻</b>：<br> ·  <a href="https://news.cnblogs.com/n/622546/" target="_blank">腾讯未成年人保护团队：不在意短期用户流失</a><br> ·  <a href="https://news.cnblogs.com/n/622562/" target="_blank">新的政策让Google Play短暂移除KDE Connect</a><br> ·  <a href="https://news.cnblogs.com/n/622556/" target="_blank">教您设定参数以默认使用私密模式启动Mozilla Firefox</a><br> ·  <a href="https://news.cnblogs.com/n/622552/" target="_blank">RedMonk编程语言榜单出炉：TypeScript和Kotlin增长迅猛</a><br> ·  <a href="https://news.cnblogs.com/n/622548/" target="_blank">鸡蛋吃得越多患心脏病风险越大？很有可能</a><br>» <a href="http://news.cnblogs.com/" title="IT新闻" target="_blank">更多新闻...</a></div></div>
<div id="HistoryToday" class="c_ad_block"></div>
<script type="text/javascript">
 if(enablePostBottom()) {
    codeHighlight();
    fixPostBody();
    setTimeout(function () { incrementViewCount(cb_entryId); }, 50);
    deliverT2();
    deliverC1();
    deliverC2();    
    loadNewsAndKb();
    loadBlogSignature();
    LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
    GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate, cb_postType);
    loadOptUnderPost();
    GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);  
}
</script>
</div>

    
	</div><!--end: forFlow -->
	</div><!--end: mainContent 主体内容容器-->

	<div id="sideBar">
		<div id="sideBarMain">
			
<!--done-->
<div class="newsItem">
<h3 class="catListTitle">公告</h3>
	<div id="blog-news"><table style="color: #f2f2f2; font-size: 1.1em; margin: 15px 0; display: none" border="0">
    <tbody><tr>
        <td>您是第</td>
        <td>
            <img style="display: block; height: 16px; margin: 0 2px" border="0" src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/counter.php" alt="AmazingCounters.com">
        </td>
        <td>位访客</td>
    </tr>
</tbody></table>

<a style="margin-top: 0px" class="flag-counter" href="https://info.flagcounter.com/77Pe"><img src="./十大经典排序算法（动图演示） - 一像素 - 博客园_files/saved_resource" alt="Flag Counter" border="0"></a>

<div class="weibo-link" style="border-bottom: 1px solid #f8f7f7; padding-bottom: 4px"><span style="font-weight: 400">微博</span>：<a style="color: #ff7300" title="博客园 | 一像素官方微博" href="https://weibo.com/u/2714741303">一像素<sup style="padding-left: 1px">more</sup></a></div><div id="profile_block">昵称：<a href="https://home.cnblogs.com/u/onepixel/">一像素</a><br>园龄：<a href="https://home.cnblogs.com/u/onepixel/" title="入园时间：2015-12-02">3年3个月</a><br>粉丝：<a href="https://home.cnblogs.com/u/onepixel/followers/">853</a><br>关注：<a href="https://home.cnblogs.com/u/onepixel/followees/">31</a><div id="p_b_follow"><a href="javascript:void(0);" onclick="follow(&#39;c25fd669-c698-e511-9fc1-ac853d9f53cc&#39;)">+加关注</a></div><script>getFollowStatus('c25fd669-c698-e511-9fc1-ac853d9f53cc')</script></div></div><script type="text/javascript">loadBlogNews();</script>
</div>

			<div id="calendar"><div id="blog-calendar" style="display:none"></div><script type="text/javascript">loadBlogDefaultCalendar();</script></div>
			
			<div id="leftcontentcontainer">
				<div id="blog-sidecolumn"><div id="sidebar_search" class="sidebar-block"></div><div id="sidebar_recentposts" class="sidebar-block">
<div class="catListEssay">
<h3 class="catListTitle">最新随笔</h3>
<ul>
<li><a href="https://www.cnblogs.com/onepixel/articles/10256314.html">1. MAC地址表、ARP缓存、FIB路由表</a></li><li><a href="https://www.cnblogs.com/onepixel/p/10238221.html">2. 中国四大骨干网与十大ISP服务商</a></li><li><a href="https://www.cnblogs.com/onepixel/p/10230697.html">3. 简述移动通信的网络制式</a></li><li><a href="https://www.cnblogs.com/onepixel/p/9272546.html">4. Linux 开启和关闭 Ping 操作</a></li><li><a href="https://www.cnblogs.com/onepixel/p/9154884.html">5. CentOS 查看和修改 Mysql 字符集</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8832776.html">6. JavaScript 内存泄露问题</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8724526.html">7. 简单介绍 CPU 的工作原理</a></li><li><a href="https://www.cnblogs.com/onepixel/articles/7717789.html">8. 正则表达式零宽断言详解</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7674659.html">9. 十大经典排序算法（动图演示）</a></li><li><a href="https://www.cnblogs.com/onepixel/articles/7605465.html">10. 详解 setTimeout、setImmediate、process.nextTick 的区别</a></li>
</ul>
</div>
</div><div id="sidebar_categories">
<div class="catListPostCategory">
<h3 class="catListTitle">随笔分类<span style="font-size:11px;font-weight:normal">(47)</span></h3>

<ul>

<li><a id="CatList_LinkList_0_Link_0" href="https://www.cnblogs.com/onepixel/category/765754.html">CSS3(3)</a> </li>

<li><a id="CatList_LinkList_0_Link_1" href="https://www.cnblogs.com/onepixel/category/1035472.html">ES6(2)</a> </li>

<li><a id="CatList_LinkList_0_Link_2" href="https://www.cnblogs.com/onepixel/category/792275.html">HTML5(4)</a> </li>

<li><a id="CatList_LinkList_0_Link_3" href="https://www.cnblogs.com/onepixel/category/792316.html">jQuery(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_4" href="https://www.cnblogs.com/onepixel/category/763999.html">JS(23)</a> </li>

<li><a id="CatList_LinkList_0_Link_5" href="https://www.cnblogs.com/onepixel/category/765775.html">Node(3)</a> </li>

<li><a id="CatList_LinkList_0_Link_6" href="https://www.cnblogs.com/onepixel/category/767134.html">React(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_7" href="https://www.cnblogs.com/onepixel/category/1065677.html">V8(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_8" href="https://www.cnblogs.com/onepixel/category/905569.html">Vue(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_9" href="https://www.cnblogs.com/onepixel/category/1193099.html">计算机原理(2)</a> </li>

<li><a id="CatList_LinkList_0_Link_10" href="https://www.cnblogs.com/onepixel/category/1193519.html">算法(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_11" href="https://www.cnblogs.com/onepixel/category/1023906.html">网络通信(5)</a> </li>

</ul>

</div>

<div class="catList">
<h3 class="catListTitle">微博</h3>

</div>

</div><div id="sidebar_scorerank" class="sidebar-block">
<div class="catListBlogRank">
<h3 class="catListTitle">积分与排名</h3>
<ul>
	<li class="liScore">
		积分 -	90397
	</li>
	<li class="liRank">
		排名 -	5158
	</li>
</ul>
</div>


</div><div id="sidebar_recentcomments" class="sidebar-block"><div id="recent_comments_wrap">
<div class="catListComment">
<h3 class="catListTitle">最新评论</h3>
	<div id="RecentCommentsBlock"><ul>
        <li class="recent_comment_title"><a href="https://www.cnblogs.com/onepixel/p/6034307.html#4211953">1. Re:Vue.js 和 MVVM 小细节</a></li>
        <li class="recent_comment_body">您好，有想法把技术知识整理成书，出版发行吗</li>
        <li class="recent_comment_author">--cr编辑</li>
        <li class="recent_comment_title"><a href="https://www.cnblogs.com/onepixel/p/7674659.html#4205189">2. Re:十大经典排序算法（动图演示）</a></li>
        <li class="recent_comment_body">这也太棒了！！！<br>转一下</li>
        <li class="recent_comment_author">--xiaozhch5</li>
        <li class="recent_comment_title"><a href="https://www.cnblogs.com/onepixel/p/7674659.html#4198340">3. Re:十大经典排序算法（动图演示）</a></li>
        <li class="recent_comment_body">转一下</li>
        <li class="recent_comment_author">--yuhui.Mr</li>
        <li class="recent_comment_title"><a href="https://www.cnblogs.com/onepixel/p/7674659.html#4188833">4. Re:十大经典排序算法（动图演示）</a></li>
        <li class="recent_comment_body">语言精辟，动画visualgo上面更简练，对我归纳有很大帮助，加快理解，谢谢作者</li>
        <li class="recent_comment_author">--张浩南</li>
        <li class="recent_comment_title"><a href="https://www.cnblogs.com/onepixel/p/7021506.html#4188010">5. Re:Web前端知识体系精简</a></li>
        <li class="recent_comment_body">很棒的总结，站的高看的远</li>
        <li class="recent_comment_author">--半夜盗贼</li>
</ul>
</div>
</div>
</div></div><div id="sidebar_topviewedposts" class="sidebar-block"><div id="topview_posts_wrap">
<div class="catListView">
<h3 class="catListTitle">阅读排行榜</h3>
	<div id="TopViewPostsBlock"><ul><li><a href="https://www.cnblogs.com/onepixel/p/7674659.html">1. 十大经典排序算法（动图演示）(276757)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5126046.html">2. 判断JS数据类型的四种方法(45344)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/6034307.html">3. Vue.js 和 MVVM 小细节(38358)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5062456.html">4. 让你分分钟理解 JavaScript 闭包(33427)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5327594.html">5. 使用 Node.js 搭建 Web 服务器(30855)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7092302.html">6. 深入浅出 TCP/IP 协议栈(30586)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5300445.html">7. H5单页面手势滑屏切换原理(21090)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5218904.html">8. JavaScript正则表达式基础(20720)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5024903.html">9. 认识原型对象和原型链(20470)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7021506.html">10. Web前端知识体系精简(20269)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5043523.html">11. 深入理解 new 操作符(19567)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5281796.html">12. JavaScript中的 NaN 与 isNaN(15320)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5248200.html">13. React 基础入门(12008)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5090799.html">14. 探索JS引擎工作原理(10099)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7143769.html">15. Node.js 事件循环机制(8464)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5156442.html">16. 快速构建H5单页面切换应用(6882)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5036369.html">17. 函数作用域和作用域链(6396)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5140944.html">18. 细说 JavaScript 七种数据类型(5793)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5143863.html">19. 深入理解 call，apply 和 bind(5565)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5097584.html">20. 浅析 jQuery 内部架构设计(3949)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5123115.html">21. 数组常用操作方法总结(3907)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7078617.html">22. requestAnimationFrame 知多少？(3245)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8724526.html">23. 简单介绍 CPU 的工作原理(2986)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7337248.html">24. 对 Undefined 与 Null 的一些理解(1858)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5141566.html">25. JavaScript 中的四舍五入(1221)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7422820.html">26. V8引擎的垃圾回收策略(1152)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8832776.html">27. JavaScript 内存泄露问题(1147)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7468343.html">28. 小端字节序与大端字节序(845)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/10238221.html">29. 中国四大骨干网与十大ISP服务商(643)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/9272546.html">30. Linux 开启和关闭 Ping 操作(461)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7159529.html">31. TTL 和 DNS TTL 的区别(275)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/9154884.html">32. CentOS 查看和修改 Mysql 字符集(165)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/10230697.html">33. 简述移动通信的网络制式(155)</a></li></ul></div>
</div>
</div></div><div id="sidebar_topcommentedposts" class="sidebar-block"><div id="topfeedback_posts_wrap">
<div class="catListFeedback">
<h3 class="catListTitle">评论排行榜</h3>
	<div id="TopFeedbackPostsBlock"><ul><li><a href="https://www.cnblogs.com/onepixel/p/5062456.html">1. 让你分分钟理解 JavaScript 闭包(81)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7674659.html">2. 十大经典排序算法（动图演示）(56)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/6034307.html">3. Vue.js 和 MVVM 小细节(43)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7021506.html">4. Web前端知识体系精简(20)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5043523.html">5. 深入理解 new 操作符(17)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7143769.html">6. Node.js 事件循环机制(16)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5327594.html">7. 使用 Node.js 搭建 Web 服务器(14)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5300445.html">8. H5单页面手势滑屏切换原理(14)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5024903.html">9. 认识原型对象和原型链(14)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5090799.html">10. 探索JS引擎工作原理(14)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5036369.html">11. 函数作用域和作用域链(11)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7092302.html">12. 深入浅出 TCP/IP 协议栈(10)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5143863.html">13. 深入理解 call，apply 和 bind(8)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5248200.html">14. React 基础入门(7)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5097584.html">15. 浅析 jQuery 内部架构设计(7)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7337248.html">16. 对 Undefined 与 Null 的一些理解(6)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5156442.html">17. 快速构建H5单页面切换应用(5)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5123115.html">18. 数组常用操作方法总结(4)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7422820.html">19. V8引擎的垃圾回收策略(2)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5218904.html">20. JavaScript正则表达式基础(2)</a></li></ul></div>
</div>
</div></div><div id="sidebar_topdiggedposts" class="sidebar-block"><div id="topdigg_posts_wrap">
<div class="catListView">
<h3 class="catListTitle">推荐排行榜</h3>
<div id="TopDiggPostsBlock"><ul><li><a href="https://www.cnblogs.com/onepixel/p/5062456.html">1. 让你分分钟理解 JavaScript 闭包(187)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7674659.html">2. 十大经典排序算法（动图演示）(117)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7021506.html">3. Web前端知识体系精简(78)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/6034307.html">4. Vue.js 和 MVVM 小细节(54)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7092302.html">5. 深入浅出 TCP/IP 协议栈(44)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5090799.html">6. 探索JS引擎工作原理(19)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5024903.html">7. 认识原型对象和原型链(19)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5218904.html">8. JavaScript正则表达式基础(15)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5143863.html">9. 深入理解 call，apply 和 bind(15)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5036369.html">10. 函数作用域和作用域链(13)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5300445.html">11. H5单页面手势滑屏切换原理(11)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7143769.html">12. Node.js 事件循环机制(11)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5043523.html">13. 深入理解 new 操作符(10)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5248200.html">14. React 基础入门(10)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5126046.html">15. 判断JS数据类型的四种方法(9)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5281796.html">16. JavaScript中的 NaN 与 isNaN(8)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7078617.html">17. requestAnimationFrame 知多少？(7)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5123115.html">18. 数组常用操作方法总结(6)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5327594.html">19. 使用 Node.js 搭建 Web 服务器(5)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5140944.html">20. 细说 JavaScript 七种数据类型(5)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5156442.html">21. 快速构建H5单页面切换应用(4)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5097584.html">22. 浅析 jQuery 内部架构设计(3)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/7422820.html">23. V8引擎的垃圾回收策略(1)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/5141566.html">24. JavaScript 中的四舍五入(1)</a></li><li><a href="https://www.cnblogs.com/onepixel/p/8724526.html">25. 简单介绍 CPU 的工作原理(1)</a></li></ul></div>
</div></div></div></div><script type="text/javascript">loadBlogSideColumn();</script>
			</div>
			
		</div><!--end: sideBarMain -->
	</div><!--end: sideBar 侧边栏容器 -->
	<div class="clear"></div>
	</div><!--end: main -->
	<div class="clear"></div>
	<div id="footer">
		
<!--done-->
Copyright ©2019 一像素
	</div><!--end: footer -->
</div><!--end: home 自定义的最大容器 -->



</body></html>